package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Elderly;
import com.ruoyi.system.mapper.ElderlyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CheckInLeaveMapper;
import com.ruoyi.system.domain.CheckInLeave;
import com.ruoyi.system.service.ICheckInLeaveService;

/**
 * 老人请假管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-02-15
 */
@Service
public class CheckInLeaveServiceImpl implements ICheckInLeaveService
{
    @Autowired
    private CheckInLeaveMapper checkInLeaveMapper;
    @Autowired
    private ElderlyMapper elderlyMapper;


    /**
     * 查询老人请假管理
     *
     * @param id 老人请假管理主键
     * @return 老人请假管理
     */
    @Override
    public CheckInLeave selectCheckInLeaveById(Long id)
    {
        return checkInLeaveMapper.selectCheckInLeaveById(id);
    }

    /**
     * 查询老人请假管理列表
     *
     * @param checkInLeave 老人请假管理
     * @return 老人请假管理
     */
    @Override
    public List<CheckInLeave> selectCheckInLeaveList(CheckInLeave checkInLeave)
    {
        return checkInLeaveMapper.selectCheckInLeaveList(checkInLeave);
    }

    /**
     * 新增老人请假管理
     *
     * @param checkInLeave 老人请假管理
     * @return 结果
     */
    @Override
    public int insertCheckInLeave(CheckInLeave checkInLeave)
    {
        checkInLeave.setCreateTime(DateUtils.getNowDate());
        Elderly elderly = elderlyMapper.selectElderlyById(checkInLeave.getPersonId());
        if(elderly != null){
            checkInLeave.setElderName(elderly.getName());
        }
        return checkInLeaveMapper.insertCheckInLeave(checkInLeave);
    }

    /**
     * 修改老人请假管理
     *
     * @param checkInLeave 老人请假管理
     * @return 结果
     */
    @Override
    public int updateCheckInLeave(CheckInLeave checkInLeave)
    {
        checkInLeave.setUpdateTime(DateUtils.getNowDate());
        Elderly elderly = elderlyMapper.selectElderlyById(checkInLeave.getPersonId());
        if(elderly != null){
            checkInLeave.setElderName(elderly.getName());
        }
        return checkInLeaveMapper.updateCheckInLeave(checkInLeave);
    }

    /**
     * 批量删除老人请假管理
     *
     * @param ids 需要删除的老人请假管理主键
     * @return 结果
     */
    @Override
    public int deleteCheckInLeaveByIds(Long[] ids)
    {
        return checkInLeaveMapper.deleteCheckInLeaveByIds(ids);
    }

    /**
     * 删除老人请假管理信息
     *
     * @param id 老人请假管理主键
     * @return 结果
     */
    @Override
    public int deleteCheckInLeaveById(Long id)
    {
        return checkInLeaveMapper.deleteCheckInLeaveById(id);
    }
}
